//
//  ByBlueToothMeaturesL2Model.m
//  laserdevice_ios
//
//  Created by pro on 17/2/14.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByBlueToothMeaturesL2Model.h"

@implementation ByBlueToothMeaturesL2Model
- (instancetype)initWithDataHexString:(NSString *)hexStr {
    
    if (self = [super initWithDataHexString:hexStr]) {
        
//        self.name = @"L2模型";
        self.name = [NSString stringWithFormat:@"L2%@", STRING(@"moxing")];

        NSString *lengthStr1 = [hexStr substringWithRange:NSMakeRange(42, 18)];
        self.lengthMin = [[self getNumberFromHexStr:lengthStr1] floatValue];
        NSString *lengthStr2 = [hexStr substringWithRange:NSMakeRange(70, 18)];
        self.lengthMax = [[self getNumberFromHexStr:lengthStr2] floatValue];
        NSString *lengthStr3 = [hexStr substringWithRange:NSMakeRange(98, 18)];
        self.lengthLast = [[self getNumberFromHexStr:lengthStr3] floatValue];
        
    }
    return self;
}

- (instancetype)initWithJsonDic:(NSDictionary *)jsonDic {
    
    if (self = [super initWithJsonDic:jsonDic]) {
        
        NSArray *attributes = jsonDic[@"attributes"];
        self.lengthMin = [attributes[0] floatValue];
        self.lengthMax = [attributes[1] floatValue];
        self.lengthLast = [attributes[2] floatValue];

    }
    return self;
}

- (NSDictionary *)saveDic {
    
    NSArray *attributes = @[[NSString stringWithFormat:@"%.6lf", self.lengthMin],
                            [NSString stringWithFormat:@"%.6lf", self.lengthMax],
                            [NSString stringWithFormat:@"%.6lf", self.lengthLast]];
    return @{@"name"        :self.name,
             @"attributes"  :attributes,};
}



- (NSString *)lengthMinStr {
    
    return [self getStringFromLength:self.lengthMin];
}
- (NSString *)lengthMaxStr {
    
    return [self getStringFromLength:self.lengthMax];
}
- (NSString *)lengthLastStr {
    
    return [self getStringFromLength:self.lengthLast];
}

@end
